package com.inibb.app.converter;

import org.apache.commons.lang.StringUtils;

import com.inibb.app.po.admin.Announcement;
import com.inibb.app.util.SecurityUtils;
import com.inibb.app.util.Sys;
import com.inibb.app.vo.admin.AnnouncementDTO;





public class AnnouncementConverter extends DTOConverter<Announcement, AnnouncementDTO> {

	@Override
	public AnnouncementDTO toDTO(Announcement po) {
		if(po==null)
			return null;
		
		AnnouncementDTO dto = new AnnouncementDTO();
		dto.setId(String.valueOf(po.getId()));
		dto.setActiveFlag(po.getActiveFlag());
		dto.setAuthor(StringUtils.trimToEmpty(po.getAuthor()));
		dto.setSubject(StringUtils.trimToEmpty(po.getSubject()));
		dto.setContent(StringUtils.trimToEmpty(po.getContent()));
		dto.setCreatedBy(StringUtils.trimToEmpty(po.getCreatedBy()));
		dto.setCreatedByFullName("");
		dto.setCreatedDate(po.getCreatedDate());
		
		return dto;
	}

	@Override
	public Announcement toPO(AnnouncementDTO dto) {
		
		if(dto==null)
			return null;
		
		Announcement po = new Announcement();
		if(!StringUtils.isBlank(dto.getId())){
			po.setId(Integer.getInteger(dto.getId()));
//			po.setUpdatedBy(SecurityUtils.getUserID());
			po.setUpdatedDate(Sys.getDate());
		}else{
			//for newly creation case:
//			po.setCreatedBy(SecurityUtils.getUserID());
			po.setCreatedDate(Sys.getDate());
		}
		po.setAuthor(dto.getAuthor());
		po.setActiveFlag(dto.getActiveFlag());
		po.setContent(dto.getContent());
		po.setSubject(dto.getSubject());
		po.setCreatedBy(StringUtils.trimToEmpty(dto.getCreatedBy()));
		return po;
	}




}
